unsigned long nr_pages;
unsigned long *page_array;
xc_dominfo_t info;
- int i, j, dump_fd;
+ int i, nr_vcpus = 0, dump_fd;
char *dump_mem, *dump_mem_start = NULL;
struct xc_core_header header;
- vcpu_guest_context_t ctxt[MAX_VIRT_CPUS];
+ vcpu_guest_context_t ctxt[MAX_VIRT_CPUS];
if ((dump_fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0) {
goto error_out;
}
- for (i = 0, j = 0; i < 32; i++)
- if (xc_domain_get_vcpu_context(xc_handle, domid, i, &ctxt[j]) == 0)
- j++;
+ for (i = 0; i < info.max_vcpu_id; i++)
+ if (xc_domain_get_vcpu_context(xc_handle, domid,
+ i, &ctxt[nr_vcpus]) == 0)
+ nr_vcpus++;
nr_pages = info.nr_pages;
header.xch_magic = 0xF00FEBED;
- header.xch_nr_vcpus = info.vcpus;
+ header.xch_nr_vcpus = nr_vcpus;
header.xch_nr_pages = nr_pages;
header.xch_ctxt_offset = sizeof(struct xc_core_header);
header.xch_index_offset = sizeof(struct xc_core_header) +
- sizeof(vcpu_guest_context_t)*info.vcpus;
+ sizeof(vcpu_guest_context_t)*nr_vcpus;
header.xch_pages_offset = round_pgup(sizeof(struct xc_core_header) +
- (sizeof(vcpu_guest_context_t) * info.vcpus) +
+ (sizeof(vcpu_guest_context_t) * nr_vcpus) +
(nr_pages * sizeof(unsigned long)));
write(dump_fd, &header, sizeof(struct xc_core_header));
- write(dump_fd, &ctxt, sizeof(ctxt[0]) * info.vcpus);
+ write(dump_fd, &ctxt, sizeof(ctxt[0]) * nr_vcpus);
if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
printf("Could not allocate memory\n");
info->max_memkb = op.u.getdomaininfo.max_pages << (PAGE_SHIFT - 10);
info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
info->cpu_time = op.u.getdomaininfo.cpu_time;
- info->vcpus = op.u.getdomaininfo.n_vcpu;
+ info->nr_online_vcpus = op.u.getdomaininfo.nr_online_vcpus;
+ info->max_vcpu_id = op.u.getdomaininfo.max_vcpu_id;
memcpy(info->handle, op.u.getdomaininfo.handle,
sizeof(xen_domain_handle_t));
return do_dom0_op(xc_handle, &op);
}
+int xc_domain_get_vcpu_info(int xc_handle,
+ uint32_t domid,
+ uint32_t vcpu,
+ xc_vcpuinfo_t *info)
+{
+ int rc;
+ dom0_op_t op;
+
+ op.cmd = DOM0_GETVCPUINFO;
+ op.u.getvcpuinfo.domain = (domid_t)domid;
+ op.u.getvcpuinfo.vcpu = (uint16_t)vcpu;
+
+ rc = do_dom0_op(xc_handle, &op);
+
+ memcpy(info, &op.u.getvcpuinfo, sizeof(*info));
+
+ return rc;
+}
+
/*
* Local variables:
* mode: C
unsigned long shared_info_frame;
uint64_t cpu_time;
unsigned long max_memkb;
- unsigned int vcpus;
+ unsigned int nr_online_vcpus;
+ unsigned int max_vcpu_id;
xen_domain_handle_t handle;
} xc_dominfo_t;
uint32_t vcpu,
vcpu_guest_context_t *ctxt);
+typedef dom0_getvcpuinfo_t xc_vcpuinfo_t;
+int xc_domain_get_vcpu_info(int xc_handle,
+ uint32_t domid,
+ uint32_t vcpu,
+ xc_vcpuinfo_t *info);
+
+
int xc_domain_setcpuweight(int xc_handle,
uint32_t domid,
float weight);
PyObject *pyhandle = PyList_New(sizeof(xen_domain_handle_t));
for ( j = 0; j < sizeof(xen_domain_handle_t); j++ )
PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j]));
- info_dict = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
+ info_dict = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
",s:l,s:L,s:l,s:i,s:i}",
"dom", info[i].domid,
- "vcpus", info[i].vcpus,
+ /* XXX 'vcpus' field is obsolete! */
+ "vcpus", info[i].nr_online_vcpus,
+ "online_vcpus", info[i].nr_online_vcpus,
+ "max_vcpu_id", info[i].max_vcpu_id,
"dying", info[i].dying,
"crashed", info[i].crashed,
"shutdown", info[i].shutdown,
return list;
}
+static PyObject *pyxc_vcpu_getinfo(PyObject *self,
+ PyObject *args,
+ PyObject *kwds)
+{
+ XcObject *xc = (XcObject *)self;
+ PyObject *info_dict;
+
+ uint32_t dom, vcpu = 0;
+ xc_vcpuinfo_t info;
+ int rc;
+
+ static char *kwd_list[] = { "dom", "vcpu", NULL };
+
+ if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
+ &dom, &vcpu) )
+ return NULL;
+
+ rc = xc_domain_get_vcpu_info(xc->xc_handle, dom, vcpu, &info);
+ if ( rc < 0 )
+ return PyErr_SetFromErrno(xc_error);
+
+ info_dict = Py_BuildValue("{s:i,s:i,s:i,s:L,s:i,s:i,s:i}",
+ "online", info.online,
+ "blocked", info.blocked,
+ "running", info.running,
+ "cpu_time", info.cpu_time,
+ "cpu", info.cpu,
+ "cpumap", info.cpumap);
+
+ return info_dict;
+}
+
static PyObject *pyxc_linux_build(PyObject *self,
PyObject *args,
PyObject *kwds)
"reason why it shut itself down.\n"
" vcpu_to_cpu [[int]]: List that maps VCPUS to CPUS\n" },
+ { "vcpu_getinfo",
+ (PyCFunction)pyxc_vcpu_getinfo,
+ METH_VARARGS | METH_KEYWORDS, "\n"
+ "Get information regarding a VCPU.\n"
+ " dom [int]: Domain to retrieve info about.\n"
+ " vcpu [int, 0]: VCPU to retrieve info about.\n\n"
+ "Returns: [dict]\n"
+ " online [int]: Bool - Is this VCPU currently online?\n"
+ " blocked [int]: Bool - Is this VCPU blocked waiting for an event?\n"
+ " running [int]: Bool - Is this VCPU currently running on a CPU?\n"
+ " cpu_time [long]: CPU time consumed, in nanoseconds\n"
+ " cpumap [int]: Bitmap of CPUs this VCPU can run on\n"
+ " cpu [int]: CPU that this VCPU is currently bound to\n" },
+
{ "linux_build",
(PyCFunction)pyxc_linux_build,
METH_VARARGS | METH_KEYWORDS, "\n"
domain->id = domaininfo[i].domain;
domain->state = domaininfo[i].flags;
domain->cpu_ns = domaininfo[i].cpu_time;
- domain->num_vcpus = domaininfo[i].n_vcpu;
+ domain->num_vcpus = domaininfo[i].nr_online_vcpus;
domain->vcpus = NULL;
domain->cur_mem =
((unsigned long long)domaininfo[i].tot_pages)
{
struct vcpu *v;
u64 cpu_time = 0;
- int vcpu_count = 0;
int flags = DOMFLAGS_BLOCKED;
info->domain = d->domain_id;
+ info->nr_online_vcpus = 0;
/*
* - domain is marked as blocked only if all its vcpus are blocked
*/
for_each_vcpu ( d, v ) {
cpu_time += v->cpu_time;
+ info->max_vcpu_id = v->vcpu_id;
if ( !test_bit(_VCPUF_down, &v->vcpu_flags) )
{
if ( !(v->vcpu_flags & VCPUF_blocked) )
flags &= ~DOMFLAGS_BLOCKED;
if ( v->vcpu_flags & VCPUF_running )
flags |= DOMFLAGS_RUNNING;
- vcpu_count++;
+ info->nr_online_vcpus++;
}
}
info->cpu_time = cpu_time;
- info->n_vcpu = vcpu_count;
info->flags = flags |
((d->domain_flags & DOMF_dying) ? DOMFLAGS_DYING : 0) |
unsigned long max_pages;
unsigned long shared_info_frame; /* MFN of shared_info struct */
uint64_t cpu_time;
- uint32_t n_vcpu;
+ uint32_t nr_online_vcpus; /* Number of VCPUs currently online. */
+ uint32_t max_vcpu_id; /* Maximum VCPUID in use by this domain. */
uint32_t ssidref;
xen_domain_handle_t handle;
} dom0_getdomaininfo_t;